﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CCMoveToAction : SSAction
{
	// 目标
	public Vector3 target;

	// 速度
	public float speed;

	public static CCMoveToAction GetSSAction(Vector3 target, float speed){
		CCMoveToAction action = ScriptableObject.CreateInstance<CCMoveToAction> ();
		action.target = target;
		action.speed = speed;
		return action;
	}

	public override void Update ()
	{
		// move
		this.transform.position = Vector3.MoveTowards (this.transform.position, target, speed * Time.deltaTime);
		// 判断是否符合移动条件
		if (this.transform.position == target) {
			//waiting for destroy
			this.destroy = true;  
			this.callback.SSActionEvent (this);
		}
	}

	public override void Start () {
	}
}

